<template>
    <div>

        <Row type="flex" :gutter="16" class="ivu-mb-8">
            <Col flex="200px"><Input v-model="domainparams.name"  placeholder="请输入站点域名/专题" clearable @on-change="domainaskData"/></Col>
            <Col flex="200px">
                <Select v-model="domainparams.type" @on-change="changeType">
                    <Option v-for="item in typeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
            </Col>
            <Col flex="100px"><Button type="primary" v-hasC="domainbutshow.add" @click="domainclick(false)">添加域名/专题</Button></Col>
        </Row>
        <JG-table
            :params="domainparams"
            :data="domaindata"
            :total="domaintotal"
            :loading="domainloading"
            :butshow="domainbutshow"
            :columns="domaincolumns"
            :disabledhover="true"
            @handleSee="domainclick"
            @askData="domainaskData"
            @handleDelete="domainhandleDelete">
        </JG-table>
        <Modal
            v-model="modaldel"
            title="删除提醒"
            @on-cancel="cancel" width="420">
            <p v-if="domainparams.type==1">确认删除该域名？</p>
            <p v-else>确认删除该专题？</p>
            <div slot="footer">
                <Button type="error" :loading="modal_loading" @click="del">确定删除</Button>
                <Button @click="cancel">取消</Button>
            </div>
        </Modal>
        <domainmodal ref="domainmodal" @askData="domainaskData"/>
        <!-- <specialmodal ref="specialmodal" @askData="specialaskData"/> -->
    </div>
</template>

<script>
    import { swtswtgetswtsite, swtswtdeleteswtsite, swtztdeletezt } from '@api/business'
    import domainmodal from './domainmodal';
    // import specialmodal from './specialmodal';
    import Select from '../../components/search/Select.vue';
    export default {
        name: 'tablename2',
        components: { domainmodal },
        data () {
            return {
                domainparams: { name: '', type: 1, page: 1, pageSize: 10 },
                domaindata: [],
                domaintotal: 0,
                domainloading: false,
                domainbutshow: {
                    Delete: {
                        name: '-v1-swt-swt-domain-zt-delete-domain-zt',
                        flag: '/v1/swt/swt-domain-zt/delete-domain-zt'

                    },
                    See: {
                        name: '-v1-swt-swt-domain-zt-update-domain-zt2',
                        flag: '/v1/swt/swt-domain-zt/update-domain-zt'
                    },
                    add: {
                        name: '-v1-swt-swt-domain-zt-update-domain-zt',
                        flag: '/v1/swt/swt-domain-zt/update-domain-zt'
                    }
                },
                domaincolumns: [
                    { title: '域名/专题', key: 'name', minWidth: 100 },
                    { title: '创建时间', key: 'created_at', width: 200 },
                    { title: '操作', slot: 'businessAdaction2', fixed: 'right', width: 120 }
                ],
                typeList: [
                    {
                        value: 1,
                        label: '域名配置'
                    },
                    {
                        value: 2,
                        label: '专题配置'
                    }
                ],
                modaldel: false,
                edit: false,
                modal_loading: false,
                params: { name: '' }
            };
        },

        mounted () {
            this.initial()
        },

        methods: {
            initial () {
                this.domainaskData()
            },
            changeType () {
                this.domainaskData()
            },
            domainaskData () {
                this.domainloading = true
                swtswtgetswtsite(this.domainparams).then(res => {
                    this.domaindata = res.list
                    this.domaintotal = res.total
                    this.domainloading = false
                })
            },
            domainclick (bool) {
                this.$refs.domainmodal.initial(bool)
            },
            domainhandleDelete (row) {
                this.edit = true
                this.params.name = row.name
                this.modaldel = true
            },
            cancel () {
                this.params = { id: '', name: '' }
                this.modaldel = false
            },
            del () {
                this.modal_loading = true
                swtswtdeleteswtsite({ name: this.params.name }).then(res => {
                    this.$Message.success('删除成功');
                    this.cancel()
                    this.domainparams.name = ''
                    this.domainaskData()
                    this.modal_loading = false
                })
            }
        }
    };
</script>

<style lang="less" scoped>

</style>
